#!/usr/bin/env python3
"""
启动 API 网关服务的脚本
"""

import subprocess
import sys
import os
from pathlib import Path

def main():
    # 获取项目根目录
    project_root = Path(__file__).parent.parent
    gateway_script = project_root / "gateway" / "api_gateway.py"
    
    # 确保在项目根目录运行
    os.chdir(project_root)
    
    # 启动 API 网关服务
    print("Starting API Gateway service...")
    print("Gateway will be available at http://127.0.0.1:8000")
    print("Press Ctrl+C to stop the service")
    
    try:
        # 使用 uv 运行网关服务
        subprocess.run([
            "uv", "run", 
            str(gateway_script)
        ], check=True)
    except subprocess.CalledProcessError as e:
        print(f"Error starting gateway service: {e}")
        sys.exit(1)
    except KeyboardInterrupt:
        print("\nGateway service stopped")
        sys.exit(0)

if __name__ == "__main__":
    main()